package com.banshuibao.bsb_android.activity;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;

import com.banshuibao.bsb_android.Constants;
import com.banshuibao.bsb_android.R;
import com.banshuibao.bsb_android.adapter.ExpertHeaderDetailAdapter;
import com.banshuibao.bsb_android.http.HttpResponse;
import com.banshuibao.bsb_android.http.HttpUtil;
import com.banshuibao.bsb_android.model.ActionModel;
import com.banshuibao.bsb_android.model.ExpertAnswerDetailModel;
import com.banshuibao.bsb_android.model.RelateDetailModel;
import com.banshuibao.bsb_android.util.GetLoginInfo;
import com.banshuibao.bsb_android.util.IntentManager;
import com.liulishuo.filedownloader.FileDownloader;

import java.util.List;

public class ExpertAnswerDetailsActivity extends BaseActivity implements View.OnClickListener {

    private RecyclerView recyclerView;
    private ExpertHeaderDetailAdapter expertAnswerDetailAdapter;
    private String uuid;
    //  private TextView ask_bt;
    private TextView send_bt;
    //   private double askPrice;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON, WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        setContentView(R.layout.activity_expert_answer_details);
        //  dataBean = (ExpertResultModel.DataBean) getIntent().getSerializableExtra("bean");
        uuid = getIntent().getStringExtra("uuid");
        //    count =dataBean.getApproveNum();
        //    title = dataBean.getQuestion();
        //     date = dataBean.getCreateDate();
        initView();
        //  getData();
    }

    @Override
    protected void onResume() {
        super.onResume();
        getData();
    }

    public void initView() {
        setTitleText("详情");
        send_bt = findViewById(R.id.menu);
        expertAnswerDetailAdapter = new ExpertHeaderDetailAdapter(ExpertAnswerDetailsActivity.this);
        //  ask_bt = findViewById(R.id.ask_bt);
        /**
         * 角色为0或3时追问按钮不显示
         */
        String role = GetLoginInfo.getLoginInfoInstance(this).readUser().getRole();
//        if (TextUtils.equals("1", role)) {
//            ask_bt.setVisibility(View.VISIBLE);
//        } else {
//            ask_bt.setVisibility(View.GONE);
//        }
        if (role.equals("0") || role.equals("2") || role.equals("3") || role.equals("4")) {
            send_bt.setVisibility(View.GONE);
        } else {
            send_bt.setVisibility(View.VISIBLE);
            send_bt.setText("申请做专家");
            send_bt.setOnClickListener(this);
        }
        //  ask_bt.setOnClickListener(this);
        recyclerView = findViewById(R.id.recyclerView);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        recyclerView.setAdapter(expertAnswerDetailAdapter);
    }

    public void getData() {
        RelateDetailModel.Body body = new RelateDetailModel.Body();
        body.setUuid(uuid);
        HttpUtil.doPost(Constants.Url.EXPERT_ANSWER_DETAIL, body, new HttpResponse(this, ExpertAnswerDetailModel.class) {
            @Override
            public void onResult(Object obj) {
                ExpertAnswerDetailModel answerDetailModel = (ExpertAnswerDetailModel) obj;
                ExpertAnswerDetailModel.DataBean dataBean = answerDetailModel.getData();
                List<ExpertAnswerDetailModel.DataBean.AsksBean> asksBeans = dataBean.getAsks();
                List<ExpertAnswerDetailModel.DataBean.VoicesBean> voices = dataBean.getVoices();
                //   askPrice = dataBean.getExpertQuUser().getAskPrice();
                //   ask_bt.setText("追问￥"+ askPrice);
                expertAnswerDetailAdapter.setHeader(voices);
                expertAnswerDetailAdapter.setBody(asksBeans);
                expertAnswerDetailAdapter.setUser(dataBean.getExpertQuUser());
                expertAnswerDetailAdapter.setAction(new ActionModel(dataBean.getExpertQuUser().getApproveNum(), uuid, dataBean.getExpertQuUser().getQuestion(), dataBean.getExpertQuUser().getCreateDate()));
            }
        });

    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
//            case R.id.ask_bt:
//                IntentManager.goQuestionCloselyActivity(ExpertAnswerDetailsActivity.this, uuid, askPrice,"expert");
//                break;
            case R.id.menu:
                IntentManager.goApplyToExpertActivity(ExpertAnswerDetailsActivity.this);
                break;
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (expertAnswerDetailAdapter != null) {
            expertAnswerDetailAdapter.clear();
        }
    }
}
